package com.yu.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yu.crm.domain.pojo.CrmEarlyWarningArea;
import com.yu.crm.mapper.CrmEarlyWarningAreaMapper;
import com.yu.crm.service.ICrmEarlyWarningAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxzz.common.config.UserCacheManager;
import com.yxzz.common.helper.DataHelpers;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author pan
 * @since 2020-07-01
 */
@Service
public class CrmEarlyWarningAreaService extends ServiceImpl<CrmEarlyWarningAreaMapper, CrmEarlyWarningArea> implements ICrmEarlyWarningAreaService {

    @Autowired
    UserCacheManager userCacheManager;

    @Override
    public List<CrmEarlyWarningArea> listInfo() {
        String userId = userCacheManager.getCurrentUser().getUserId();
        QueryWrapper<CrmEarlyWarningArea> wrapper = new QueryWrapper<>();
//        wrapper.eq("create_user_id",userId);
        return this.list(wrapper);
    }

    @Override
    public void addOrUpdate(CrmEarlyWarningArea area) {
        if(DataHelpers.isNotEmpty(area.getId())){
            area.setGmtModified(LocalDateTime.now());
        }else{
            area.setCreateUserId(userCacheManager.getCurrentUser().getUserId());
            area.setGmtCreate(LocalDateTime.now());
            area.setGmtModified(LocalDateTime.now());
        }
        this.saveOrUpdate(area);
    }
}
